package cr5xdll;

import javax.swing.JFrame;
import javax.swing.JOptionPane;

import com.maszy.bean.CashRegister;
import com.maszy.bean.Log;

public class CR5XFrame extends JFrame {
	CR5X cr5x = new CR5X();

	// 注册收银机
	public boolean regObj(CashRegister cr) {		
		System.out.println(">>>>>>开始调用cr5x");
		cr5x.InitJavaEnv(new String("cr5xdll/CR5XFrame"));
		boolean b = cr5x.RegECRUdp(Integer.parseInt(cr.getCashRegister_NO()),
				cr.getCashRegister_IP(), Long.toString(cr.getDoorStore_Id()),
				5002, false);
		return b;
	}


	public void InitObj() {
		cr5x.CreateTransObj();
		cr5x.StartComRecvDataThd();
	}

	public void FreeObj() {
		cr5x.StopComRecvDataThd();
		cr5x.FreeTransObj();
		System.out.println(">>>>>>cr5x调用结束，释放内存。");
	}

	// 添加操作信息
	private void AppendMsg(int msgType, int iEcrId, String sIp, int iPort,
			int iPackNo, int iTaskId, String sPercent, String sLog) {
		System.out.println("iEcrId=" + iEcrId + " msgType=" + msgType + " sIp="
				+ sIp + " iPort=" + iPort + " iTaskId=" + iTaskId
				+ " sPercent=" + sPercent + " sLog=" + sLog);
		if (msgType == 4) {
			// JOptionPane.showMessageDialog(this, "Task: " + iTaskId + " OK");
			System.out.println("Task:" + iTaskId + " OK!");
			Log.l = "OK";
		} else if (msgType == 5) {
			// JOptionPane.showMessageDialog(this, "Task: " + iTaskId +
			// " Fail");
			System.out.println("Task:" + iTaskId + " Fail!");
			Log.l = "Fail";
		}
	}

	// 上传日销售明细HEX文件
	public int TransUpTrRpt(int iEcrId, String sFileName, String sLogFileName) {
		int i = cr5x.TransUpTrRpt(iEcrId, sFileName, sLogFileName);
		return i;
	}

	// 上传会员卡消费明细HEX文件
	public int TransUpRFID(int iEcrId, String sFileName, String sLogFileName) {
		int i = cr5x.TransUpRFID(iEcrId, sFileName, sLogFileName);
		// System.out.println(">>>>上传RFID消费明细HEX文件："+iEcrId+"\t"+sFileName+"\t"+sLogFileName);
		return i;
	}

	// 日销售明细HEX转为TXT文件
	public boolean SaleDetailRptHexToTxt(String sHexFile, String sMainTxtFile,
			String sDetailTxtFile, String sPayTxtFile, String sErrFile,
			boolean bShowProgress) {
		boolean b = cr5x.SaleDetailRptHexToTxt(sHexFile, sMainTxtFile,
				sDetailTxtFile, sPayTxtFile, sErrFile, false);
		// System.out
		// .println("********************************************************************");
		// System.out.println("cr5xdll.CR5XFrame.SaleDetailRptHexToTxt()");
		// System.out.println("sHexFile=" + sHexFile);
		// System.out.println("sMainTxtFile=" + sMainTxtFile);
		// System.out.println("sDetailTxtFile=" + sDetailTxtFile);
		// System.out.println("sPayTxtFile=" + sPayTxtFile);
		// System.out.println("sErrFile=" + sErrFile);
		// System.out.println("bShowProgress=" + bShowProgress);
		// System.out
		// .println("********************************************************************");
		return b;
	}

	// RFID会员卡HEX转为TXT文件
	public boolean RFIDHexToTxt(String sHexFile, String sTxtFile,
			String sErrFile, boolean bShowProgress) {
		boolean b = cr5x.RFIDHexToTxt(sTxtFile, sHexFile, sErrFile,
				bShowProgress);
		System.out
				.println("********************************************************************");
		System.out.println("cr5xdll.CR5XFrame.RFIDHexToTxt()");
		System.out.println("sHexFile=" + sHexFile);
		System.out.println("sMainTxtFile=" + sTxtFile);
		System.out.println("sErrFile=" + sErrFile);
		System.out.println("bShowProgress=" + bShowProgress);
		System.out
				.println("********************************************************************");
		return b;
	}

}
